package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author liangzai
 * @Description:
 */
public class CardDemo {
    public static final char[] suit = {'♥','♣','♠','♦'};

    public void buycrad(List<Crad> list){
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                Crad crad = new Crad(i,suit[j]);
                list.add(crad);
            }
        }
    }

    private void swap(List<Crad> list, int i,int j){
        Crad tmp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,tmp) ;
    }

    public void shuffle(List<Crad> list){
        Random random = new Random();
        for (int i = list.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(list,i,index);
        }
    }

    public void play(List<List <Crad>> player,List<Crad> list){
        List<Crad> player1 = new ArrayList<>();
        List<Crad> player2 = new ArrayList<>();
        List<Crad> player3 = new ArrayList<>();
        player.add(player1);
        player.add(player2);
        player.add(player3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                player.get(j).add(list.get(0));
                list.remove(0);
            }
        }
    }
}
